package cn.hhchat.wp.enums;

import cn.hhchat.wp.exception.InValidFieldsException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created this one by HMH on 2017/10/22.
 */
public enum SexEnum {

    男,
    女
    ;

    private static final Map<String, SexEnum> stringToEnum = new HashMap<>();
    static{
        for(SexEnum e : values()){
            stringToEnum.put(e.name(), e);
        }
    }

    public static SexEnum fromString(String name,String fieldName){
        SexEnum result = stringToEnum.get(name);
        if (result == null) {
            throw new InValidFieldsException(fieldName + "枚举字段错误");
        }
        return result;
    }

    public static List<String> list(){
        return new ArrayList<>(stringToEnum.keySet());
    }

}
